package org.ainlolcat.ainscience.statistics.handlers.hitran.instfunc;

import static java.lang.Math.PI;

/**
 * @author ainlolcat
 *         Date: 5/1/13
 */
public class GaussInstrumentalFunction implements InstrumentalFunction{
    double w;
    double A = 1;
    double y0 = 0;

    public GaussInstrumentalFunction() {
    }

    public GaussInstrumentalFunction( double y0, double A, double w){
        this.w = w;
        this.A = A;
        this.y0 = y0;
    }

    public GaussInstrumentalFunction(double w){
        this.w = w;
    }

    public void setParameters(double[] params) {
        this.w = params[0];
        this.A = params[1];
        this.y0 = params[2];
    }

    public double getValue(double dx) {
        return  y0 + (A/(w*Math.sqrt(PI/2)))*Math.exp(-2 * Math.pow(dx, 2) / (Math.pow(w, 2)));
    }

    public boolean equals(Object o){
        if (o instanceof GaussInstrumentalFunction){
            return w == ((GaussInstrumentalFunction)o).w;
        }
        return false;
    }
}
